package com.tz.online.book.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.tz.online.book.dao.ICategoryDao;
import com.tz.online.entity.Category;
import com.tz.online.util.HibernateCallback;
import com.tz.online.util.HibernateTemplate;

public class CategoryDaoImpl implements ICategoryDao {
	
	private HibernateTemplate template = new HibernateTemplate();

	public CategoryDaoImpl() {
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Category> getAll() {
		return (List<Category>) template.execute(new HibernateCallback() {
			
			@Override
			public Object doInHibernate(Session ses) throws HibernateException {
				return ses.createQuery("from Category")
						.list();
			}
		});
	}

}
